import Express from "express"
import {
    addArtServ,
    findArtByPageServ
} from '../Service/articleServ.js';
import {findArtByIdServ} from "../Service/articleServ.js"
export const articleRouter = Express.Router();
// Restful
articleRouter.get('/', async (req, res) => {
    const {page,size,searchValue,type} = req.query;
    const queryobj = {

    };
    if(searchValue){
        queryobj.title =searchValue;
    }
    if(type){
        queryobj.typeId =type;
    }
    const result = await findArtByPageServ(page, size, queryobj)
    res.json(result)
})
articleRouter.post('/', async (req, res) => {
    const result = await addArtServ(req.body);
    res.json(result)
})

articleRouter.get("/:id",async(req,res)=>{
    const result =await findArtByIdServ(req.params.id)
    res.json(result)
})

